home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 283 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  70 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: claus@faerber.muc.de (Claus A. Faerber)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Give operator. a chance
  5. Date: 05 Feb 1996 14:59:10 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <62HLdPo3cDB@faerber.muc.de>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Mon, 5 Feb 1996 01:00:00 +0100
  11. In-Reply-To: <3102AD11.1663@et.se>
  12. X-Mailer: CrossPoint v3.1 R/B17071
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMRaL0Ey4NqrwXLNJAQHgKQH9G9ZiCYu4kbvigXppjwBEkCyhbyrwBWGq
  15.     h8htHtxf66+saixZgQlqueXUlaBJNdwWWzlJgKCRhtA0hOQAUqA3Hg==
  16.     =U0MR
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. IMO there's a better way than 'operator.()':
  20.  
  21. Simply say: 'If a class member identifier is not found  
  22. within an object, all possible cast operators are scanned in  
  23. order to find a conversion to an object of a class  
  24. containing a member with this identifier.'
  25.  
  26. Eg.:
  27.  
  28. class A{
  29. public: void A();
  30.         void C();
  31. }
  32.  
  33. class B{
  34. public:
  35.         void B();
  36.         void C();
  37.         void D();
  38. }
  39.  
  40. class C{
  41.         A* pA;
  42.         B* pB;
  43. public:
  44.         void D();
  45.  
  46.         A& operator A&() { return *pA; };
  47.         B& operator B&() { return *pB; };
  48. }
  49.  
  50. //
  51.  
  52. C c;
  53.  
  54. c.A();  // calls ((A&)c).A();
  55. c.B();  // calls ((B&)c).B();
  56.  
  57. c.C();  // calls ((A&)c).C();, as operator A& is first
  58.  
  59. c.D();  // calls c.D();, as D() is already member of C
  60.  
  61. Claus
  62.  
  63. ------------------------------------------------------------------------
  64. Claus Andre Faerber - claus@faerber.muc.de - http://www.muc.de/~cfaerber
  65. ------------------------------------------------------------------------
  66. ---
  67. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  68.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  69.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  70.